import 'dart:async';
import 'package:audioplayers/audioplayers.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:getx_scaffold/getx_scaffold.dart';
import 'package:azring/core/repository/default_api.dart';
import 'package:azring/core/models/relax_info.dart';
import 'package:azring/common/utils/url_utils.dart';
import 'sleep_aid_state.dart';

/// 助眠控制器
class SleepAidLogic extends GetxController {
  /// 状态实例
  final SleepAidState state = SleepAidState();
  
  /// 计时器
  Timer? _timer;
  Timer? _breathingTimer;
  
  /// 滚动控制器
  FixedExtentScrollController? scrollController;

  /// 音频播放器
  final AudioPlayer _audioPlayer = AudioPlayer();

  /// API实例
  final DefaultApi _api = DefaultApi();

  /// 助眠类型值（从路由参数获取）
  String? _relaxTypeValue;

  @override
  void onInit() {
    super.onInit();
    
    // 从路由参数获取 relaxType
    final args = Get.arguments as Map<String, dynamic>?;
    _relaxTypeValue = args?['relaxType'];
    print('助眠页面接收到 relaxType: $_relaxTypeValue');
    
    // 初始化滚动控制器，默认选中第4项（5分钟）
    scrollController = FixedExtentScrollController(initialItem: 4);
    _initializeBreathing();
    // 加载助眠场景列表
    loadRelaxScenes();
    // 加载频次列表
    loadFrequencies();
    // 启动默认呼吸动画
  }

  @override
  void onClose() {
    _timer?.cancel();
    _breathingTimer?.cancel();
    scrollController?.dispose();
    _audioPlayer.dispose();
    super.onClose();
  }

  /// 加载助眠场景列表
  Future<void> loadRelaxScenes() async {
    try {
      state.isLoading.value = true;
      final response = await _api.queryRelaxInfoListGet<Map<String, dynamic>>(
        relaxType: 'az_relax_type',
        isShowLoading: false,
      );

      if (response != null && response['code'] == 200) {
        final List<dynamic> data = response['data'] ?? [];
        state.relaxScenes.value = data
            .map((item) => RelaxInfo.fromJson(item as Map<String, dynamic>))
            .toList();
        
        // 默认选中第一个场景并开启环境音效
        if (state.relaxScenes.isNotEmpty) {
          state.selectedScene.value = state.relaxScenes.first;
          state.isAmbientSoundOn.value = true; // 默认开启环境音效
        }
      }
    } catch (e) {
      print('加载助眠场景失败: $e');
      Toast.show('加载场景失败');
    } finally {
      state.isLoading.value = false;
    }
  }

  /// 加载频次列表
  Future<void> loadFrequencies() async {
    try {
      // 使用从路由参数获取的 relaxType，如果没有则使用默认值
      final relaxType = _relaxTypeValue ?? 'az_relax_type';
      print('加载频次列表，使用 relaxType: $relaxType');
      
      final response = await _api.queryRelaxFrequencyListGet<Map<String, dynamic>>(
        relaxType: relaxType,
        isShowLoading: false,
      );

      if (response != null && response['code'] == 200) {
        final List<dynamic> data = response['data'] ?? [];
        state.frequencies.value = data
            .map((item) => RelaxFrequency.fromJson(item as Map<String, dynamic>))
            .toList();
        
        print('加载频次列表成功: ${state.frequencies.length} 条');
        
        // 加载完成后，更新当前选择分钟数对应的呼吸次数
        _updateBreathingFrequency();
      }
    } catch (e) {
      print('加载频次列表失败: $e');
    }
  }

  /// 初始化呼吸练习
  void _initializeBreathing() {
    state.currentPhase.value = 4;
    state.currentCount.value = 5;
    state.totalPhases.value = 8;
    _updateBreathingFrequency(); // 初始化时更新呼吸次数
    state.remainingTime.value = 0;
    state.circleSize.value = 140.0; // 更小的初始大小
    state.completedCycles.value = 0;
  }

  /// 更新选中的时间
  void updateSelectedTime(int index) {
    state.selectedMinutes.value = index + 1; // index从0开始，所以+1
    // 根据选择的分钟数更新呼吸次数
    _updateBreathingFrequency();
  }

  /// 根据分钟数更新选中的时间
  void updateSelectedTimeByMinute(int minutes) {
    state.selectedMinutes.value = minutes;
    // 根据选择的分钟数更新呼吸次数
    _updateBreathingFrequency();
  }

  /// 根据选择的分钟数更新呼吸次数
  void _updateBreathingFrequency() {
    final minutes = state.selectedMinutes.value;
    // 从频次列表中查找对应的呼吸次数
    final frequency = state.frequencies.firstWhereOrNull(
      (freq) => freq.minutes == minutes,
    );
    
    if (frequency != null && frequency.frequency != null) {
      state.breathingFrequency.value = frequency.frequency!;
      state.breathingInstruction.value = '${frequency.frequency}次';
    } else {
      // 如果没有找到，使用默认计算方式（每个循环19秒）
      state.breathingFrequency.value = (minutes * 60 / 19).round();
      state.breathingInstruction.value = '${state.breathingFrequency.value}次';
    }
  }

  /// 加载呼吸节点列表
  Future<void> loadBreathingNodes() async {
    try {
      final minutes = state.selectedMinutes.value;
      print('加载呼吸节点列表，分钟数: $minutes');
      
      final response = await _api.querySleepAidListGet<Map<String, dynamic>>(
        minutes: minutes,
        isShowLoading: false,
      );

      if (response != null && response['code'] == 200) {
        final List<dynamic> data = response['data'] ?? [];
        state.breathingNodes.value = data
            .map((item) => BreathingNode.fromJson(item as Map<String, dynamic>))
            .toList();
        
        // 计算总秒数
        if (state.breathingNodes.isNotEmpty) {
          state.totalSeconds.value = state.breathingNodes.last.seconds;
        }
        
        print('加载呼吸节点成功: ${state.breathingNodes.length} 个节点');
      }
    } catch (e) {
      print('加载呼吸节点失败: $e');
    }
  }

  /// 开始呼吸练习
  void startBreathing() async {
    // 先加载呼吸节点
    await loadBreathingNodes();
    
    if (state.breathingNodes.isEmpty) {
      Toast.show('加载呼吸节点失败，请重试');
      return;
    }
    
    state.isActive.value = true;
    state.startTime = DateTime.now();
    state.elapsedSeconds.value = 0;
    
    // 设置初始指令
    _updateBreathingInstruction();
    
    // 如果选中了场景且开启了音效，播放音频
    print('开始呼吸练习 - 环境音效开关: ${state.isAmbientSoundOn.value}, 选中场景: ${state.selectedScene.value?.relaxName}');
    if (state.isAmbientSoundOn.value && state.selectedScene.value != null) {
      print('准备播放环境音效');
      await _playAmbientSound();
    } else {
      print('不播放音效 - 原因: ${!state.isAmbientSoundOn.value ? "音效未开启" : "未选择场景"}');
    }
    
    _startBreathingTimer();
  }

  /// 暂停呼吸练习
  void pauseBreathing() {
    state.isPaused.value = true;
    _timer?.cancel();
    state.breathingInstruction.value = '已暂停';
    
    // 暂停音频
    _audioPlayer.pause();
  }
  
  /// 继续呼吸练习
  void resumeBreathing() {
    state.isPaused.value = false;
    
    // 继续音频
    if (state.isAmbientSoundOn.value && state.selectedScene.value != null) {
      _audioPlayer.resume();
    }
    
    // 继续计时
    _startBreathingTimer();
  }

  /// 停止呼吸练习
  void stopBreathing() {
    state.isActive.value = false;
    _timer?.cancel();
    _breathingTimer?.cancel();
    _initializeBreathing();
    
    // 停止音频
    _audioPlayer.stop();
  }

  /// 开始呼吸计时器
  void _startBreathingTimer() {
    _timer = Timer.periodic(const Duration(seconds: 1), (timer) {
      if (!state.isActive.value) {
        timer.cancel();
        return;
      }
      
      state.elapsedSeconds.value++;
      
      // 更新呼吸指令
      _updateBreathingInstruction();
      
      // 检查是否完成
      if (state.elapsedSeconds.value >= state.totalSeconds.value) {
        timer.cancel();
        _completeSession();
      }
    });
  }

  /// 更新呼吸指令
  void _updateBreathingInstruction() {
    final elapsed = state.elapsedSeconds.value;
    
    // 查找当前秒数对应的呼吸指令
    BreathingNode? currentNode;
    BreathingNode? nextNode;
    
    for (int i = 0; i < state.breathingNodes.length; i++) {
      final node = state.breathingNodes[i];
      if (node.seconds <= elapsed) {
        currentNode = node;
        if (i + 1 < state.breathingNodes.length) {
          nextNode = state.breathingNodes[i + 1];
        }
      } else {
        break;
      }
    }
    
    if (currentNode != null) {
      // 检测呼吸阶段是否变化
      final previousInstruction = state.breathingInstruction.value;
      final newInstruction = currentNode.value;
      
      // 如果阶段发生变化，触发震动
      if (previousInstruction != newInstruction && 
          (newInstruction == '吸气' || newInstruction == '屏住呼吸' || newInstruction == '呼气')) {
        HapticFeedback.heavyImpact();
      }
      
      state.breathingInstruction.value = newInstruction;
      
      // 根据呼吸指令调整圆圈大小
      if (currentNode.value == '吸气') {
        state.circleSize.value = 180.0;
        state.animationDuration.value = nextNode != null 
            ? (nextNode.seconds - currentNode.seconds) * 1000 
            : 4000;
      } else if (currentNode.value == '屏住呼吸') {
        state.circleSize.value = 180.0; // 保持大小
        state.animationDuration.value = 1000;
      } else if (currentNode.value == '呼气') {
        state.circleSize.value = 120.0;
        state.animationDuration.value = nextNode != null 
            ? (nextNode.seconds - currentNode.seconds) * 1000 
            : 8000;
      }
      
      // 计算剩余时间
      if (nextNode != null) {
        state.remainingTime.value = nextNode.seconds - elapsed;
      } else {
        state.remainingTime.value = state.totalSeconds.value - elapsed;
      }
    }
  }

  /// 完成整个练习
  void _completeSession() {
    state.isActive.value = false;
    state.breathingInstruction.value = '助眠练习完成！';
    
    // 停止音频
    _audioPlayer.stop();
    
    // 显示完成提示
    Toast.show('恭喜！您已完成助眠呼吸练习，祝您好梦！');
    
    // 重置状态
    Future.delayed(const Duration(seconds: 3), () {
      _initializeBreathing();
    });
  }

  /// 播放环境音效
  Future<void> _playAmbientSound() async {
    try {
      final scene = state.selectedScene.value;
      print('尝试播放音频 - 场景: ${scene?.relaxName}, 路径: ${scene?.relaxFilePath}');
      
      if (scene?.relaxFilePath != null) {
        final audioUrl = UrlUtils.toFullFileUrl(scene!.relaxFilePath);
        print('完整音频URL: $audioUrl');
        
        // 先设置循环模式
        await _audioPlayer.setReleaseMode(ReleaseMode.loop);
        // 再播放音频
        await _audioPlayer.play(UrlSource(audioUrl));
        print('音频播放成功');
      } else {
        print('音频路径为空，无法播放');
      }
    } catch (e) {
      print('播放音频失败: $e');
      Toast.show('播放音频失败，请检查网络连接');
    }
  }

  /// 切换环境音效
  void toggleAmbientSound() {
    state.isAmbientSoundOn.value = !state.isAmbientSoundOn.value;
    
    if (state.isAmbientSoundOn.value) {
      if (state.isActive.value) {
        _playAmbientSound();
      }
      final sceneName = state.selectedScene.value?.relaxName ?? '环境音效';
      Toast.show('$sceneName已开启');
    } else {
      _audioPlayer.stop();
      Toast.show('环境音效已关闭');
    }
  }

  /// 选择场景
  void selectScene(RelaxInfo scene) {
    state.selectedScene.value = scene;
    
    // 停止当前音频
    _audioPlayer.stop();
    
    // 如果环境音效已开启，立即播放新场景的音频
    if (state.isAmbientSoundOn.value) {
      _playAmbientSound();
    }
    
    Get.back(); // 关闭场景选择弹窗
  }

  /// 显示场景选择弹窗
  void showSceneSelector() {
    Get.bottomSheet(
      Container(
        height: Get.height * 0.65,
        decoration: BoxDecoration(
          color: const Color(0xFF282528).withOpacity(0.95),
          borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
        ),
        child: Column(
          children: [
            // 标题栏
            Padding(
              padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 24.h),
              child: Text(
                '声音场景',
                style: TextStyle(
                  fontSize: 18.sp,
                  fontWeight: FontWeight.w500,
                  color: Colors.white,
                ),
              ),
            ),
            // 场景列表
            Expanded(
              child: Obx(() {
                if (state.isLoading.value) {
                  return const Center(
                    child: CircularProgressIndicator(color: Colors.white),
                  );
                }
                
                if (state.relaxScenes.isEmpty) {
                  return Center(
                    child: Text(
                      '暂无场景',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colors.white60,
                      ),
                    ),
                  );
                }
                
                return GridView.builder(
                  padding: EdgeInsets.symmetric(horizontal: 20.w, vertical: 10.h),
                  gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                    crossAxisCount: 3,
                    crossAxisSpacing: 16.w,
                    mainAxisSpacing: 20.h,
                    childAspectRatio: 0.75,
                  ),
                  itemCount: state.relaxScenes.length,
                  itemBuilder: (context, index) {
                    final scene = state.relaxScenes[index];
                    final isSelected = state.selectedScene.value == scene;
                    
                    return GestureDetector(
                      onTap: () => selectScene(scene),
                      child: Column(
                        children: [
                          // 场景图片
                          Container(
                            width: 100.w,
                            height: 100.w,
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(12.r),
                              border: isSelected
                                  ? Border.all(color: Colors.white, width: 2)
                                  : null,
                            ),
                            child: ClipRRect(
                              borderRadius: BorderRadius.circular(12.r),
                              child: Stack(
                                fit: StackFit.expand,
                                children: [
                                  Image.network(
                                    UrlUtils.toFullImageUrl(scene.relaxImage),
                                    fit: BoxFit.cover,
                                    errorBuilder: (context, error, stackTrace) {
                                      return Container(
                                        color: Colors.grey[800],
                                        child: Icon(
                                          Icons.image_not_supported,
                                          size: 30.sp,
                                          color: Colors.grey[600],
                                        ),
                                      );
                                    },
                                  ),
                                  // 选中状态的播放图标
                                  if (isSelected)
                                    Container(
                                      color: Colors.black.withOpacity(0.3),
                                      child: Center(
                                        child: Icon(
                                          Icons.pause,
                                          color: Colors.white,
                                          size: 32.sp,
                                        ),
                                      ),
                                    ),
                                ],
                              ),
                            ),
                          ),
                          SizedBox(height: 8.h),
                          // 场景名称
                          Text(
                            scene.relaxName ?? '未命名',
                            style: TextStyle(
                              fontSize: 14.sp,
                              color: Colors.white,
                              fontWeight: FontWeight.w400,
                            ),
                            textAlign: TextAlign.center,
                            maxLines: 1,
                            overflow: TextOverflow.ellipsis,
                          ),
                        ],
                      ),
                    );
                  },
                );
              }),
            ),
            // 关闭按钮
            Padding(
              padding: EdgeInsets.only(bottom: 30.h, top: 10.h),
              child: GestureDetector(
                onTap: () => Get.back(),
                child: Container(
                  width: 50.w,
                  height: 50.w,
                  decoration: BoxDecoration(
                    color: Colors.white.withOpacity(0.2),
                    shape: BoxShape.circle,
                  ),
                  child: Icon(
                    Icons.close,
                    color: Colors.white,
                    size: 24.sp,
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
    );
  }

  

  /// 显示助眠指导菜单
  /// 显示助眠指导菜单
  void showMenu() {
    Get.bottomSheet(
      Container(
        height: Get.height * 0.9,
        decoration: BoxDecoration(
          color: Colors.black,
          borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
        ),
        child: Column(
          children: [
            // 顶部星空图片区域
            Stack(
              children: [
                Container(
                  height: 200.h,
                  decoration: BoxDecoration(
                    gradient: const LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [Color(0xFF1A1A3E), Color(0xFF2D1B3D)],
                    ),
                    borderRadius: BorderRadius.vertical(top: Radius.circular(20.r)),
                  ),
                  child: Stack(
                    children: [
                      // 星星装饰
                      Positioned(
                        top: 30.h,
                        left: 30.w,
                        child: _buildStar(size: 4.sp),
                      ),
                      Positioned(
                        top: 50.h,
                        right: 40.w,
                        child: _buildStar(size: 3.sp),
                      ),
                      Positioned(
                        top: 90.h,
                        left: 120.w,
                        child: _buildStar(size: 5.sp),
                      ),
                      Positioned(
                        bottom: 40.h,
                        right: 100.w,
                        child: _buildStar(size: 4.sp),
                      ),
                      Positioned(
                        top: 120.h,
                        right: 200.w,
                        child: _buildStar(size: 3.sp),
                      ),
                    ],
                  ),
                ),
                // 关闭按钮
                Positioned(
                  top: 16.h,
                  right: 16.w,
                  child: GestureDetector(
                    onTap: () => Get.back(),
                    child: Container(
                      padding: EdgeInsets.all(8.w),
                      decoration: BoxDecoration(
                        color: Colors.white.withOpacity(0.2),
                        shape: BoxShape.circle,
                      ),
                      child: Icon(
                        Icons.close,
                        color: Colors.white,
                        size: 20.sp,
                      ),
                    ),
                  ),
                ),
              ],
            ),
            // 内容区域
            Expanded(
              child: SingleChildScrollView(
                padding: EdgeInsets.all(20.w),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      '助眠',
                      style: TextStyle(
                        fontSize: 24.sp,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                    SizedBox(height: 16.h),
                    Text(
                      '4-7-8呼吸法是一种简单有效的助眠技巧，通过调节呼吸节奏帮助身心放松。',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colors.grey[600],
                        height: 1.5,
                      ),
                    ),
                    SizedBox(height: 8.h),
                    Text(
                      '这种呼吸法可以降低心率，平静神经系统，让您更容易进入睡眠状态。',
                      style: TextStyle(
                        fontSize: 16.sp,
                        color: Colors.grey[600],
                        height: 1.5,
                      ),
                    ),
                    SizedBox(height: 32.h),
                    Text(
                      '呼吸技巧',
                      style: TextStyle(
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                    SizedBox(height: 20.h),
                    _buildBreathingStep(
                      icon: Icons.airline_seat_legroom_normal,
                      title: '姿势',
                      description: '躺在床上或坐在舒适的位置，背部挺直。将舌尖轻轻抵住上颚前牙后方。',
                      color: const Color(0xFF6A4C93),
                    ),
                    SizedBox(height: 16.h),
                    _buildBreathingStep(
                      icon: Icons.air,
                      title: '吸气 (4秒)',
                      description: '用鼻子安静地吸气，心中默数4秒。',
                      color: const Color(0xFF6A4C93),
                    ),
                    SizedBox(height: 16.h),
                    _buildBreathingStep(
                      icon: Icons.pause_circle_outline,
                      title: '屏息 (7秒)',
                      description: '屏住呼吸，心中默数7秒。',
                      color: const Color(0xFF6A4C93),
                    ),
                    SizedBox(height: 16.h),
                    _buildBreathingStep(
                      icon: Icons.air,
                      title: '呼气 (8秒)',
                      description: '用嘴慢慢呼气，发出"呼"的声音，心中默数8秒。',
                      color: const Color(0xFF6A4C93),
                    ),
                    SizedBox(height: 32.h),
                    Text(
                      '补充说明',
                      style: TextStyle(
                        fontSize: 20.sp,
                        fontWeight: FontWeight.bold,
                        color: Colors.white,
                      ),
                    ),
                    SizedBox(height: 16.h),
                    // 插图区域
                    Container(
                      height: 120.h,
                      decoration: BoxDecoration(
                        gradient: const LinearGradient(
                          begin: Alignment.topLeft,
                          end: Alignment.bottomRight,
                          colors: [Color(0xFF6A4C93), Color(0xFF8B6FA8)],
                        ),
                        borderRadius: BorderRadius.circular(12.r),
                      ),
                      child: Center(
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Container(
                              width: 60.w,
                              height: 60.h,
                              decoration: BoxDecoration(
                                color: Colors.white.withOpacity(0.8),
                                shape: BoxShape.circle,
                              ),
                              child: Icon(
                                Icons.nights_stay,
                                color: const Color(0xFF6A4C93),
                                size: 30.sp,
                              ),
                            ),
                            SizedBox(height: 8.h),
                            Text(
                              '放松身心，安然入睡',
                              style: TextStyle(
                                fontSize: 14.sp,
                                color: Colors.white,
                                fontWeight: FontWeight.w500,
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                    SizedBox(height: 32.h),
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
      isScrollControlled: true,
    );
  }

  /// 获取当前场景的背景渐变色
  List<Color> getBackgroundGradient() {
    final sceneName = state.selectedScene.value?.relaxName;
    
    switch (sceneName) {
      case '烤火':
        return [
          const Color(0xFF1A1A1A),
          const Color(0xFF8B4513),
          const Color(0xFF2F1B14),
        ];
      case '溪流':
        return [
          const Color(0xFF1A3A52),
          const Color(0xFF4A90A4),
          const Color(0xFF2C5F75),
        ];
      case '鸟鸣':
        return [
          const Color(0xFF2D4A2B),
          const Color(0xFF5C8D89),
          const Color(0xFF3A5F4C),
        ];
      case '海浪':
        return [
          const Color(0xFF1B3A5F),
          const Color(0xFF3A7CA5),
          const Color(0xFF2E5984),
        ];
      case '雨滴':
        return [
          const Color(0xFF2C3E50),
          const Color(0xFF5D6D7E),
          const Color(0xFF34495E),
        ];
      case '大风':
        return [
          const Color(0xFF34495E),
          const Color(0xFF7F8C8D),
          const Color(0xFF566573),
        ];
      default:
        // 助眠默认紫色系
        return [
          const Color(0xFF1A1A1A),
          const Color(0xFF6A4C93),
          const Color(0xFF4A3B7A),
        ];
    }
  }
}


  

  /// 构建星星装饰
  Widget _buildStar({required double size}) {
    return Container(
      width: size,
      height: size,
      decoration: BoxDecoration(
        color: Colors.white.withOpacity(0.8),
        shape: BoxShape.circle,
        boxShadow: [
          BoxShadow(
            color: Colors.white.withOpacity(0.5),
            blurRadius: size * 2,
            spreadRadius: size / 2,
          ),
        ],
      ),
    );
  }

  /// 构建呼吸步骤
  Widget _buildBreathingStep({
    required IconData icon,
    required String title,
    required String description,
    required Color color,
  }) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          padding: EdgeInsets.all(8.w),
          decoration: BoxDecoration(
            color: color.withOpacity(0.1),
            shape: BoxShape.circle,
          ),
          child: Icon(
            icon,
            color: color,
            size: 20.sp,
          ),
        ),
        SizedBox(width: 12.w),
        Expanded(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                title,
                style: TextStyle(
                  fontSize: 16.sp,
                  fontWeight: FontWeight.w600,
                  color: Colors.black87,
                ),
              ),
              SizedBox(height: 4.h),
              Text(
                description,
                style: TextStyle(
                  fontSize: 14.sp,
                  color: Colors.grey[600],
                  height: 1.5,
                ),
              ),
            ],
          ),
        ),
      ],
    );
  }

 
